/*
 * Copyright (c) Huawei Technologies Co., Ltd. 2020-2021. All rights reserved.
 * Description: remote_access头文件
 * Author: hanwei
 * Create: 2020-7-21
 */

#include "remote_access.h"
#include <algorithm>
#include "remote_access_impl.h"

namespace hccl {
using namespace std;

RemoteAccess::RemoteAccess()
{
}

RemoteAccess::~RemoteAccess()
{
    impl_ = nullptr;
}

HcclResult RemoteAccess::Init(u32 rank, const vector<MemRegisterAddr>& addrInfos,
                              const RmaRankTable &rankTable)
{
    impl_.reset(new (std::nothrow) RemoteAccessImpl());
    CHK_PTR_NULL(impl_);
    CHK_RET(impl_->Init(rank, addrInfos, rankTable));
    return HCCL_SUCCESS;
}

HcclResult RemoteAccess::RemoteRead(const vector<HcomRemoteAccessAddrInfo>& addrInfos, HcclRtStream stream)
{
    CHK_PTR_NULL(impl_);
    CHK_PTR_NULL(stream);
    CHK_RET(impl_->RemoteRead(addrInfos, stream));
    return HCCL_SUCCESS;
}

HcclResult RemoteAccess::RemoteWrite(const vector<HcomRemoteAccessAddrInfo>& addrInfos, HcclRtStream stream)
{
    CHK_PTR_NULL(impl_);
    CHK_PTR_NULL(stream);
    CHK_RET(impl_->RemoteWrite(addrInfos, stream));
    return HCCL_SUCCESS;
}
}